<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once APPLICATION_PATH.'/misc/additional.php';
require_once APPLICATION_PATH.'/misc/sessionController.php';
class Application_Controllers_Admin_ActionRegisterController
{   public $wrongMessage="";
    //validation before registration
    public function preRegistration($form){

    }
    //action on registration
    public function onRegistration($form){
        $admins = new Application_Model_DbTable_Admin();
        $role = new Application_Model_DbTable_Role();
        $sessionController = new sessionController();
        $additional = new Additional();
        $actionLog = new Application_Model_DbTable_Actionlog();
        //Generate Randon Password
        $password = $additional->rand_str(6);
        //generate username
        $tempArrray = explode(' ', $form->getValue('name'));
        $username = $tempArrray[0];
        $temp=1;
        while(!$admins->checkUser($username)){
            $username = $tempArrray[0].$temp;
            $temp++;
        }
                $admins->addAdmin($form->getValue("name"),
                        $username,
                        $form->getValue("email"),
                        $form->getValue("phone"),
                        sha1($password),
                        $form->getValue("details"),
                        $form->getValue("role"));
        $actionLog->addActionLog($sessionController->getSessionLogId(),
                                         "[".$_SERVER['REMOTE_ADDR'].
                                         "][Super Admin] Add User Nama:".
                                         $form->getValue('name').
                                        ",Username:".$form->getValue('username')
                                         .",Role: ".$role->getRoleName($form->getValue('role')));
         $body = "YTH ".$form->getValue("name").",\n".
                 "Anda telah terdaftar di dalam bitz-plaza sebagai ".
                  $role->getRoleName($form->getValue('role'))." \n".
                 "Dengan Rincian sebagai berikut:\n".
                 "Username :".$username."\n".
                 "Password :".$password."\n".
                 "Mohon klik link berikut untuk Masuk Ke dalam Bitz-Plaza \n".
                 "http://localhost/bitz-plaza/admin/";
         $subject="Pendaftaran admin Bitz-Plaza";
         $additional->sendEmail($body, 
                 array($form->getValue("email")=>$form->getValue("name"))
                 ,$subject);

    }
    public function postRegister($username,$password){
        
    }
}
?>
